@<template>
  <div id="goodslistitem" @click="goodItemClick">
    <div>
      <img :src="showImage" alt="" @load="imgLoad" />

      <div>
        <p>{{ goodsItem.title }}</p>
        <span class="price">{{ goodsItem.price }}</span>
        <span class="collect"> ♡ {{ goodsItem.cfav }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  created() {
    this.iid = this.goodsItem.iid;
  },
  props: {
    goodsItem: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data(){
    return {
      count: 0,
      iid: 0,
    }
  },
  methods: {
    imgLoad() {
      
     
      if(this.$route.path.indexOf('/home') != -1){
         //通过事件总线 发出图片加载事件
        this.$bus.$emit('imgLoad')
      }else if (this.$route.path.indexOf('/detail') != -1){
        this.$bus.$emit('detailImgLoad')
      }
       
    },
    goodItemClick(){
      this.$router.push('/detail/'+ this.iid)
    }
  },
  computed: {
    showImage() {
      return this.goodsItem.image || this.goodsItem.show.img
    }
  }
};
</script>

<style>
#goodslistitem {
  width: 50%; 
  /* padding: 10px 5px 10px 2px; */
  
}
#goodslistitem p {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}
.price {
    color: red;
}
#goodslistitem img {
    border-radius: 8px;
    width: 100%;
}

</style>